package coder.nav.controller;

import coder.nav.common.JwtToken;
import coder.nav.common.R;
import coder.nav.model.bo.NavIdeBO;
import coder.nav.model.bo.NavIdeRunBO;
import coder.nav.model.vo.NavIdeRunOutErrVO;
import coder.nav.model.vo.NavKeyValueVO;
import coder.nav.service.NavIdeService;
import coder.nav.service.NavTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "编辑器")
@RestController
@RequestMapping("/ide")
public class NavIdeController {

    @Autowired
    private NavIdeService ideService;

    @ApiOperation("编辑器-执行")
    @PostMapping("/run")
    public R<NavIdeRunOutErrVO> save(@Validated @RequestBody NavIdeRunBO bo) {
        return new R<>(ideService.run(bo));
    }

    @JwtToken
    @ApiOperation("编辑器-语言-下拉列表")
    @GetMapping("/getLangList")
    public R<List<NavKeyValueVO<String, String>>> getLangList() {
        return new R<>(ideService.getLangList());
    }

    @JwtToken
    @ApiOperation("编辑器-获取代码缓存")
    @GetMapping("/getIde")
    public R<String> getIde(@RequestParam("lang") String lang) {
        return new R<>(ideService.getIde(lang));
    }

    @JwtToken
    @ApiOperation("编辑器-保存代码缓存")
    @PostMapping("/saveIde")
    public R<NavIdeRunOutErrVO> saveIde(@Validated @RequestBody NavIdeBO bo) {
        ideService.saveIde(bo);
        return new R<>();
    }

}
